﻿using System;
using System.ServiceModel.Channels;

namespace Microsoft.Biztalk.Adapters.Wcf.NullBinding
{
    class NullChannelFactory<TChannel> : ChannelFactoryBase<TChannel> where TChannel : class, IChannel
    {
        NullBindingProperties properties;

        public NullChannelFactory(NullBindingProperties properties)
        {
            this.properties = properties;
        }

        protected override TChannel OnCreateChannel(System.ServiceModel.EndpointAddress address, Uri via)
        {
            if (typeof(TChannel) == typeof(IOutputChannel))
            {
                return (TChannel)(object)(new NullOutputChannel(this, this.properties));
            }
            else
            {
                return (TChannel)(object)(new NullRequestChannel(this, this.properties));
            }
        }

        protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
        {
            return new NullAsyncResult(callback, state);
        }

        protected override void OnEndOpen(IAsyncResult result)
        {
        }

        protected override void OnOpen(TimeSpan timeout)
        {
        }
    }
}
